package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Category;
import com.itheima.domain.Movies;
import com.itheima.service.CategoryService;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(value = "{http://127.0.0.1:81,http://127.0.0.1:82}")
@RestController
@RequestMapping("/movies")
public class MoviesManagerController {
    @Autowired
    private MoviesService moviesService;
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/findByPage")
    public PageInfo<Movies> findByPage(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize,Integer cid,String keyword){
        return moviesService.findByPage(pageNum,pageSize,cid,keyword);
    }
    @GetMapping("/findAll")
    public List<Movies> findAll(){
        return moviesService.findAll();
    }
   //添加
    @PostMapping("/add")
    public String add(@RequestBody Movies movies){
        //调用方法
        moviesService.save(movies);
        return "ok";
    }
    //根据id回显
    @GetMapping("/findById")
    public Movies findById(Integer id){
        //调用方法
        return moviesService.findById(id);
    }
    //根据Id删除
    @DeleteMapping("/deleteById")
    public String deleteById(Integer id){
        //调用方法
        moviesService.deleteById(id);
        return "ok";
    }
    //批量删除
    @DeleteMapping("deleteIds")
    public String deleteIds(Integer[] ids){
        //调用方法
        moviesService.deleteIds(ids);
        return "ok";
    }
    //查找所有分类
   /* @GetMapping("/findCategory")
    public List<Category> findCategory(){
        //调用方法
       return categoryService.findAll();
    }*/
}
